package com.shilei.strategy;

/**
 * @description: 排序
 * @author: 81271
 * @date: 2020-04-12 10:58
 */
public class Sorter<T> {

    public void sort(T[] arr, Comparator<T> comparator) {
        for (int i = 0; i< arr.length -1; i++) {
            int minPos = i;

            for (int j =i+1; j<arr.length; j++) {
                minPos = comparator.compareTo(arr[j], arr[minPos]) == -1? j :minPos;
            }
            swap(arr, i, minPos);
        }

    }

    private void swap(T[] arr, int i, int j) {
        T temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
